package com.kkb.service.impl;

import com.kkb.mapper.TbImageMapper;
import com.kkb.pojo.TbImage;
import com.kkb.pojo.TbImageExample;
import com.kkb.service.TbImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbImageServiceImpl implements TbImageService {

    @Autowired
    private TbImageMapper tbImageMapper;

    @Override
    public String getImgUrl(Integer goodsId) {
        TbImageExample example = new TbImageExample();
        TbImageExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(goodsId);
        List<TbImage> tbImages = tbImageMapper.selectByExample(example);
        //goodsId只有一个或者没有，所以取get(0)
        if(tbImages.size()>0){
            return tbImages.get(0).getImgPath();
        }
        return null;
    }
}
